<?php
/**
 * Created by PhpStorm.
 * User: iraklis
 * Date: 1/19/14
 * Time: 2:10 AM
 */
include 'config.php';
include 'db_connection.php';

$day = getdate();
$alert = $day['year'] . '-' . $day['mon'] . '-' . $day['yday'];

$query = mysql_query("SELECT * FROM USERS;");

while ($users = mysql_fetch_assoc($query)) {
    $u_id = $users['u_id'];
    $mail = $users['email'];
    $query2 = mysql_query("SELECT * FROM REMINDERS_RECURRANCY WHERE DATE(start) = '$alert' AND u_id = '$u_id';");

    while($reminders_rec = mysql_fetch_assoc($query2)){

        $subject = $reminders_rec['title'];
        $message = $reminders_rec['description'];
        $to = $mail;
        $from = "RemindMe";
        $subject = $_POST['subject'];
        $message = $_POST['message'];
        mail($to, "Subject: $subject", $message, "From: $from" );
    }

}// end of while

/*$host = "ssl://smtp.googlemail.com";
$port = "465";
$username = "irtsoup@gmail.com";
$password = "81iraklis92@!";*/